﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using GalaSoft.MvvmLight.Messaging;

namespace Songhay.Silverlight.BiggestBox.IndexPart.Views.UserControls
{
    /// <summary>
    /// User Control for DataGrid Row Details Sample
    /// </summary>
    public partial class DataGridRowDetails : UserControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="DataGridRowDetails"/> class.
        /// </summary>
        public DataGridRowDetails()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Handles the Loaded event of the GridRowToggle control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param>
        void GridRowToggle_Loaded(object sender, RoutedEventArgs e)
        {
            if(!(sender is ToggleButton)) return;

            Messenger.Default.Register<bool>(this,
            message =>
            {
                var button = sender as ToggleButton;
                button.IsChecked = message;
            });
        }
    }
}
